package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mapper.NoticeMapper;
import com.example.mapper.QuestionMapper;
import com.example.mapper.UserMapper;
import com.example.model.LoginUser;
import com.example.model.Notice;
import com.example.model.Question;
import com.example.model.User;
import com.example.vo.thumbupVO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author by admin, Email xx@xx.com, Date on 2020/5/22.
 * PS: Not easy to write code, please indicate.
 */
@Service
public class NoticeService {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private NoticeMapper noticeMapper;
    @Autowired
    private UserMapper userMapper;

    public List<thumbupVO>  getMyNotice(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Long id = loginUser.getUser().getId();
        List<thumbupVO> thumbupVOlist = new ArrayList<>();
        List<Notice> myNotice= noticeMapper.selectList(new QueryWrapper<Notice>().eq("receiver_Id", id));
        myNotice.forEach(i->{
            thumbupVO thumbupVO = new thumbupVO();
            Question question = questionMapper.getquetionByid(i.getTargetId());
            User user = userMapper.selectById(i.getOperatorId());
            thumbupVO.setQuestion(question);
            thumbupVO.setUser(user);
            thumbupVOlist.add(thumbupVO);
        });
        return thumbupVOlist;
    }



}
